<template>
  <Center>
    <h1>正在验证中...</h1>
  </Center>
</template>

<script>
import Center from '@/components/Center'
import { mapState } from 'vuex'
export default {
  name: 'Auth',
  components: {
    Center
  },
  computed: mapState('loginUser', ['data', 'isLoading']),
  methods: {
    handleData () {
      if (!this.isLoading) {
        if (this.data) {
          if (this.$route.query.returnurl) {
            this.$router.push(this.$route.query.returnurl)
          } else {
            this.$router.push({ name: 'Home' })
          }
        } else {
          this.$router.push({ name: 'Login' })
        }
      }
    },
    handleIsLoading () {
      if (!this.isLoading && !this.data) {
        this.$router.push({ name: 'Login' })
      }
    }
  },
  watch: {
    data: {
      immediate: true,
      handler () {
        this.handleData()
      }
    },
    isLoading: {
      immediate: true,
      handler () {
        this.handleIsLoading()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
h1 {
  font-size: 2em;
}
</style>
